<template>
	<view style="height: 100vh;display: flex;flex-direction: column;">
		<view style="flex: 1;display: flex;height: 100%;padding: 30rpx 50px;align-items: flex-end;">
			<text style="color: black;font-weight: bold;font-size: 20px;">账号密码登录</text>
		</view>
		<view style="flex: 3;">
			<view style="padding: 0 50px;">
				<u-form labelPosition="left" :model="form" :rules="rules" ref="uForm" labelWidth="auto" errorType="border-bottom" bo>
					<u-form-item prop="employe_tel" borderBottom>
						<u-input v-model="form.employe_tel" type="number" placeholder="请输入用户名"></u-input>
					</u-form-item>
					<u-form-item prop="employe_password" borderBottom>
						<u-input v-model="form.employe_password" password  placeholder="请输入密码"></u-input>
					</u-form-item>
					<view style="margin-top: 20px;">
						<u-button type="primary" shape="circle"  @click="onsubmit" >登陆</u-button>
					</view>
				</u-form>
			</view>
			<view style="color: #909399;text-align: center;margin-top: 50px;">
				<view style="display: flex;justify-content: center;">
					<view style="width: 375rpx;">
						<u-divider text="欢迎合作" :hairline="true"></u-divider>
					</view>
				</view>
				<view style="display: flex;justify-content: center;">
					<text>新ICP备案 2020001434号</text>
				</view>
				<view style="display: flex;justify-content: center;margin-top: 20rpx;">
					<u-avatar size="60" :src="logo"></u-avatar>
				</view>
			</view>
		</view>
		<u-toast ref="uToast"></u-toast>
		<myModal ref="myModal"></myModal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				logo: require('@/static/logo_zheng.png'),
				rules: {
					'employe_tel': {
						type: 'string',
						required: true,
						message: '请输入用户名',
						trigger: ['blur', 'change']
					},
					'employe_password': {
						type: 'string',
						required: true,
						message: '请输入密码',
						trigger: ['blur', 'change']
					},
				},
				form: {
					employe_tel: '',
					employe_password: ''
				}
			}
		},
		mounted() {
			// this.$refs['myModal'].show('啦啦啦','内容啦啦啦');
			
		},
		methods: {
			onsubmit() {
				var that = this;

				uni.login({
					provider: 'weixin', //使用微信登录
					success: function(loginRes) {
						console.log(loginRes);
						that.form.wxLoginCode=loginRes.code;
						that.$refs.uForm.validate().then(res => {
							that.$http.post('/employe/login', that.form, (res) => {
								if (res.data.success) {
									that.$refs.uToast.show({
										title: '登录成功',
										type: "success",
										callback() {
											uni.switchTab({
												url: '/pages/index/index'
											});
										}
									});
									// that.$refs.myModal.hide();
									uni.setStorageSync('token', res.data.result.token);
								} else {
									that.$refs.myModal.show('登录失败', res.data.result.message);
								}
							});
						})
					}
				});
				
			}
		}
	}
</script>

<style>
	page {
		background: white;
	}
</style>